$(document).ready(function(){
    $('form').submit ( function () {
        ($("#name")).parent().parent().children().eq(2).remove();
        ($("#email")).parent().parent().children().eq(2).remove();
        if ( $("#name").val() == "") 
            {
                $($("#name")).parent().parent().append ("<td class=\"signup\">Name is required </td>");
                return false;
            }
        if ( $("#email").val() != "" ) {
            var result = verifyemailaddress ($("#email").val());
            if ( result != 1 ) { 
                $($("#email")).parent().parent().append (result);
                return false;
            }    
        }
        return true;
    });
    function verifyemailaddress(emailaddressVal) {
        if ( emailaddressVal == null || emailaddressVal.length < 1 || emailaddressVal.length > 255)
            return "<td class=\"signup\">Email address is required </td>";

        var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;
        if ( !emailReg.test(emailaddressVal)) 
            return "<td class=\"signup\">Enter a valid email address </td>";
        else
            return 1;
    }
});